*****************************************************************
* Local Partisan Biases in Allocations of Foreign Aid: 
* A Study of Agricultural Assistance in India
*
* Brian Min, Eugenio Arima, David Backer, Allen Hicken, Ken Kollman, and Joel Selway 
* World Politics, 2023 no. 1
*
*
* CONSTITUENCY-LEVEL ANALYSIS
* Replication code for: 
* Tables 1,2,3,5,8,9
* Appendix Table 5
* Appendix Figure 2
*
* Rev 7 July 2022
*****************************************************************

	
			
set more off 
clear all
use "AC_India_AgAid_ts_full_20190730_v13.dta", clear

* Create interaction effects 
gen projonXalign_both=project_ongoing*align_both
gen projonXalign_st=project_ongoing*align_st
gen projonXalign_ce=project_ongoing*align_ce

gen projstXalign_both=project_start*align_both
gen projstXalign_st=project_start*align_st
gen projstXalign_ce=project_start*align_ce

gen close=mov<3
gen closeXalign_both=close*align_both
gen closeXalign_st=close*align_st
gen closeXalign_ce=close*align_ce

gen movXalign_both=mov*align_both
gen movXalign_st=mov*align_st
gen movXalign_ce=mov*align_ce

gen bjpXalign_both=bjp*align_both	
gen bjpXalign_st=bjp*align_st	
gen bjpXalign_ce=bjp*align_ce	

gen cpXalign_both=cp*align_both	
gen cpXalign_st=cp*align_st	
gen cpXalign_ce=cp*align_ce	

gen othpXalign_both=othp*align_both	
gen othpXalign_st=othp*align_st	
gen othpXalign_ce=othp*align_ce	
	
*******************************************
* TABLE 1 
* Partisan Alignment with Ruling Parties at State and/or National Level of Constituencies Receiving World Bank Agricultural Aid in India, 1995-2008
 
forvalues y=1995/2008 {
	tab project_start if align_both==1 & year==`y'
	tab project_start if align_ce==1 & year==`y'
	tab project_start if align_st==1 & year==`y'
	tab project_start if align_none==1 & year==`y'
	}

tab project_start if year!=1994 & areakm2!=. 
tab project_start if align_both==1 &  year!=1994 & areakm2!=.
tab project_start if align_st==1  & year!=1994 & areakm2!=.
tab project_start if align_ce==1  & year!=1994 & areakm2!=.
tab project_start if align_none==1 & year!=1994 & areakm2!=. 
 
distinct stac_id_num if project_start==1 & year!=1994 & areakm2!=.
distinct stac_id_num if project_start==1 & align_both==1 & year!=1994 & areakm2!=.
distinct stac_id_num if project_start==1 & align_ce==1 & year!=1994 & areakm2!=.
distinct stac_id_num if project_start==1 & align_st==1 & year!=1994 & areakm2!=.
distinct stac_id_num if project_start==1 & align_none==1 & year!=1994 & areakm2!=.


 
*******************************************
* TABLE 2
* Descriptive Stats
estpost summarize  project_start project_ongoing areakm2 SPI12m ///
	demmean mean_slope riverkm rdunsp c3km2 c4km2 c3_pct c4_pct ///
	electionyear turnout mov align_st align_ce align_both align_none ///
	bjp cp inc othp if year!=1994 & areakm2!=.
esttab, cells("count mean sd min max")
 


*******************************************
* TABLE 3
* Explaining the Allocation of Agricultural Aid (Constituency-Level)
*
* DV: Agricultural Aid-Funded Project Start in constituency	
		
	* Model 1			
	xtlogit project_start l.c3_pct l.c4_pct l.SPI12m i.year, fe

	* Model 2			
	xtlogit project_start l.c3_pct l.c4_pct l.SPI12m i.l.align_both i.l.align_ce i.l.align_st l.electionyear l.turnout l.mov i.year, fe

	* Model 3	
	xtlogit project_start l.c3_pct l.c4_pct l.SPI12m i.l.align_both i.l.align_ce i.l.align_st l.electionyear l.turnout l.mov l.bjp l.cp l.othp i.year, fe
			

		* To calculate marginal effects of key vars:
		margins, dydx(_all)
		margins i.l.align_both
		test 0.l.align_both=1.l.align_both
		margins i.l.align_ce
		test 0.l.align_both=1.l.align_ce

		
		
*******************************************
* TABLE 5	
* Testing Mechanisms of Alignment on Agricultural Aid Allocation (Constituency-Level) 


	* Model 1: Close elections (MoV<3)
	xtlogit project_start c3_pct c4_pct l.SPI12m l.electionyear l.turnout l.align_st l.align_ce l.align_both l.close l.closeXalign_both l.closeXalign_st l.closeXalign_ce i.year, fe
	
	* Model 2: Close elections (MoV<3) w/ parties
	xtlogit project_start c3_pct c4_pct l.SPI12m l.electionyear l.turnout l.align_st l.align_ce l.align_both l.close l.closeXalign_both l.closeXalign_st l.closeXalign_ce  l.bjp l.cp l.othp i.year, fe

	* Model 3: Margin of victory
	xtlogit project_start c3_pct c4_pct l.SPI12m l.electionyear l.turnout l.align_st l.align_ce l.align_both l.mov l.movXalign_both l.movXalign_st l.movXalign_ce i.year, fe

	* Model 4: Margin of victory w/ parties
	xtlogit project_start c3_pct c4_pct l.SPI12m l.electionyear l.turnout l.align_st l.align_ce l.align_both l.mov l.movXalign_both l.movXalign_st l.movXalign_ce  l.bjp l.cp l.othp i.year, fe
		
	* Model 5: Party interactions 
	xtlogit project_start c3_pct c4_pct l.SPI12m l.electionyear l.turnout l.align_st l.align_ce l.align_both  l.bjp l.cp l.othp l.bjpX* l.cpX* l.othpX* i.year, fe
		


*******************************************
* TABLE 8
* New Starts of World Bank-Funded Agriculture Projects following Changes in the Partisan Alignment of State Legislative Assembly Constituencies in India, 1995-2008

	sum project_start

		* Not aligned to Not aligned
	sum project_start if align_none==1 & l.align_none==1


		* Aligned both, previously unaligned
	sum project_start if align_both==1 & l.align_none==1
		* Aligned both, previously align_st
	sum project_start if align_both==1 & l.align_st==1
		* Aligned both, previously unaligned
	sum project_start if align_both==1 & l.align_ce==1


		* Aligned central, previously unaligned
	sum project_start if align_ce==1 & l.align_none==1
		* Aligned central, previously align_st
	sum project_start if align_ce==1 & l.align_st==1
		* Aligned central, previously align_both
	sum project_start if align_ce==1 & l.align_both==1

		* Aligned state, previously unaligned
	sum project_start if align_st==1 & l.align_none==1
		* Aligned state, previously align_ce
	sum project_start if align_st==1 & l.align_ce==1
		* Aligned state, previously align_both
	sum project_start if align_st==1 & l.align_both==1


		* Unaligned, previously aligned both
	sum project_start if align_none==1 & l.align_both==1 
		* Unaligned, previously aligned central
	sum project_start if align_none==1 & l.align_ce==1 
		* Unaligned, previously aligned state
	sum project_start if align_none==1 & l.align_st==1 


		* subtotals, effect of previous alignment status
	sum project_start if (align_both==1 | align_st==1 | align_ce==1) & l.align_none==1 
	sum project_start if (align_both==1 | align_none==1 | align_ce==1) & l.align_st==1
	sum project_start if (align_both==1 | align_st==1 | align_none==1) & l.align_ce==1
	sum project_start if (align_none==1 | align_st==1 | align_ce==1) & l.align_both==1

		* subtotals, effect of new alignment status 
	sum project_start if (l.align_both==1 | l.align_st==1 | l.align_ce==1) & align_none==1
	sum project_start if (l.align_both==1 | l.align_none==1 | l.align_ce==1) & align_st==1
	sum project_start if (l.align_both==1 | l.align_st==1 | l.align_none==1) & align_ce==1
	sum project_start if (l.align_none==1 | l.align_st==1 | l.align_ce==1) & align_both==1



		

*******************************************
* TABLE 9
* Effects of agricultural aid projects on cropland coverage in India
	
	* Model 1
	xtreg c3_pct00 i.l.project_ongoing l.project_start l.SPI12m i.year, fe

	* Model 2
	xtreg c3_pct00 i.l.project_ongoing l.project_start l.SPI12m l.electionyear l.turnout l.mov l.align_st l.align_ce l.align_both l.bjp l.cp l.othp i.year, fe

	* Model 3
	xtreg c3_pct00 l.SPI12m l.electionyear l.turnout l.mov  i.l.project_ongoing##i.l.align_st  i.l.project_ongoing##i.l.align_ce i.l.project_ongoing##i.l.align_both i.l.project_start##i.l.align_st  i.l.project_start##i.l.align_ce i.l.project_start##i.l.align_both l.bjp l.cp l.othp  i.year, fe
				
		* To calculate marginal effects of key vars:
		margins, dydx(_all)
		margins i.l.project_ongoing i.l.project_start i.l.align_st i.l.align_ce i.l.align_both
		margins r.l.project_ongoing r.l.project_start r.l.align_st r.l.align_ce r.l.align_both
		test 0.l.align_both=1.l.align_both
		test 0.l.project_ongoing=1.l.project_ongoing

		margins i.l.project_ongoing
	
		* Interaction effects show that cropland INCREASES with align_both and align_ce
		margins i.l.project_ongoing##i.l.align_st
		margins i.l.project_ongoing##i.l.align_ce
		margins i.l.project_ongoing##i.l.align_both

					
	* Model 4
	xtreg c4_pct00 i.l.project_ongoing l.project_start l.SPI12m i.year, fe

	* Model 5
	xtreg c4_pct00 l.project_ongoing l.project_start l.SPI12m l.electionyear l.turnout l.mov l.align_st l.align_ce l.align_both l.bjp l.cp l.othp i.year, fe

	* Model 6
	xtreg c4_pct00 l.SPI12m l.electionyear l.turnout l.mov  i.l.project_ongoing##i.l.align_st  i.l.project_ongoing##i.l.align_ce i.l.project_ongoing##i.l.align_both i.l.project_start##i.l.align_st  i.l.project_start##i.l.align_ce i.l.project_start##i.l.align_both l.bjp l.cp l.othp  i.year, fe

		* To calculate marginal effects of key vars:
		margins, dydx(_all)
		margins i.l.project_ongoing i.l.project_start i.l.align_st i.l.align_ce i.l.align_both
		margins r.l.project_ongoing r.l.project_start r.l.align_st r.l.align_ce r.l.align_both
		test 0.l.align_both=1.l.align_both
		test 0.l.project_ongoing=1.l.project_ongoing

		* Interaction effects show that cropland INCREASES with align_both and align_ce
		margins i.l.project_ongoing##i.l.align_st
		margins i.l.project_ongoing##i.l.align_ce
		margins i.l.project_ongoing##i.l.align_both

		

*******************************************
* APPENDIX TABLE 5
* Robustness check for Table 7
* Project starts 2 years after change in alignment

	* Not aligned to Not aligned
sum project_start if align_none==1 & l2.align_none==1

	* Aligned both, previously unaligned
sum project_start if align_both==1 & l2.align_none==1
	* Aligned both, previously align_st
sum project_start if align_both==1 & l2.align_st==1
	* Aligned both, previously align_ce
sum project_start if align_both==1 & l2.align_ce==1


	* Aligned central, previously unaligned
sum project_start if align_ce==1 & l2.align_none==1
	* Aligned central, previously align_st
sum project_start if align_ce==1 & l2.align_st==1
	* Aligned central, previously align_both
sum project_start if align_ce==1 & l2.align_both==1


	* Aligned state, previously unaligned
sum project_start if align_st==1 & l2.align_none==1
	* Aligned state, previously align_ce
sum project_start if align_st==1 & l2.align_ce==1
	* Aligned state, previously align_both
sum project_start if align_st==1 & l2.align_both==1


	* Unaligned, previously aligned state
sum project_start if align_none==1 & l2.align_st==1 
	* Unaligned, previously aligned central
sum project_start if align_none==1 & l2.align_ce==1 
	* Unaligned, previously aligned both
sum project_start if align_none==1 & l2.align_both==1 
	

*******************************************
* APPENDIX FIGURE 2 
* C3 and C4 Cropland Change per World Bank Project ID

sort year
levelsof project_id, local(projcodes) 
foreach l of local projcodes{
	di "c3_pct" 
	egen p25c3_`l'=pctile(c3_pct00), p(25), if project_id=="`l'", by(year) 
	egen meanc3_`l'=mean(c3_pct00) if project_id=="`l'", by(year) 
	egen p75c3_`l'=pctile(c3_pct00), p(75), if project_id=="`l'", by(year) 
	twoway rarea p25c3_`l' p75c3_`l' year, ylabel(0(25)100) ytitle("") color(gs14) legend(off) || ///
		line meanc3_`l' year, ylabel(0(25)100) ytitle("") name(g3`l', replace) title("`l'") legend(off)  
	local graphs3 "`graphs3' g3`l'"
	}
graph combine `graphs3', title("C3 Cropland", size(medsmall))


levelsof project_id, local(projcodes) 
foreach l of local projcodes{
	di "c4_pct" 
	egen p25c4_`l'=pctile(c4_pct00), p(25), if project_id=="`l'",  by(year) 
	egen meanc4_`l'=mean(c4_pct00) if project_id=="`l'", by(year) 
	egen p75c4_`l'=pctile(c4_pct00), p(75), if project_id=="`l'", by(year) 
	twoway rarea p25c4_`l' p75c4_`l' year, ylabel(0(25)100) ytitle("") color(gs14) legend(off) || ///
		line meanc4_`l' year, ylabel(0(25)100) ytitle("") name(g4`l', replace) title("`l'") legend(off)  
	local graphs4 "`graphs4' g4`l'"
	}	
graph combine `graphs4', title("C4 Cropland", size(medsmall))
	

	

